package cn.dt70.service.impl;

import cn.dt70.dao.aqbNewproject.AqbNewprojectMapper;
import cn.dt70.pojo.AqbNewproject;
import cn.dt70.service.AqbNewprojectService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class AqbNewprojectServiceImpl implements AqbNewprojectService {

    private static final Logger LOGGER = Logger.getLogger(AqbNewprojectServiceImpl.class);

    @Resource
    private AqbNewprojectMapper aqbNewprojectMapper;

    @Override
    public boolean addNewGiftLog(Integer userId) {

        boolean flag = false;

        try {
            int row = aqbNewprojectMapper.saveNewGiftLog(userId);
            if (row == 1) {
                flag = true;
            }
        } catch (Exception e) {
            LOGGER.error("AqbNewprojectServiceImpl.addNewGiftLog --> " + e.getMessage());
        }

        return flag;
    }

    @Override
    public boolean findNewGiftLogByUserId(Integer userId) {
        boolean noExist = false;
        try {
            if (null == aqbNewprojectMapper.selectNewGiftLogByUserId(userId)) {
                noExist = true;
            }

        } catch (Exception e) {
            LOGGER.error("AqbNewprojectServiceImpl.findNewGiftLogByUserId --> " + e.getMessage());
        }

        return noExist;
    }

    @Override
    public boolean modifyBalance(BigDecimal interest, Integer userId) {
        boolean flag = false;

        try {
            int row = aqbNewprojectMapper.updateBalance(aqbNewprojectMapper.selectNewGiftLogByUserId(userId).getBalance().add(interest),userId);
            if (row == 1) {
                flag = true;
            }
        } catch (Exception e) {
            LOGGER.error("AqbNewprojectServiceImpl.modifyBalance --> " + e.getMessage());
        }

        return flag;
    }

}
